import 'package:flutter/material.dart';
import 'package:flutter_oldman_health/pages/map/map_type_show_page.dart';

class MapFunctionSelectWidget extends StatefulWidget {
  String mapTypeStr = "普通地图";
  List<String> expandTypeSelectList1 = ["3D楼宇"];

  MapFunctionSelectWidgetState mapFunctionSelectWidgetState;
  ShowMapTypePageState showMapTypePageState;

  MapFunctionSelectWidget(
      this.showMapTypePageState, this.mapTypeStr, this.expandTypeSelectList1);

  @override
  State<StatefulWidget> createState() {
    mapFunctionSelectWidgetState = MapFunctionSelectWidgetState(
        showMapTypePageState, mapTypeStr, expandTypeSelectList1);
    return mapFunctionSelectWidgetState;
  }

  String get mapTypeString {
    return mapFunctionSelectWidgetState.mapTypeString;
  }

  String get localTypeString {
    return mapFunctionSelectWidgetState.localTypeString;
  }

  List<String> get expandTypeSelectList {
    return mapFunctionSelectWidgetState.expandTypeSelectList;
  }
}

class MapFunctionSelectWidgetState extends State<MapFunctionSelectWidget> {
  List<String> mapTypeList = ["普通地图", "卫星地图"];
  List<String> localTypeList = ["标准模式", "跟随模式", "罗盘模式"];
  List<String> expandTypeList = ["路况图", "热力图"]; //, "3D楼宇"
  List<String> expandTypeSelectList = [];//"3D楼宇"

  String mapTypeString = "普通地图";
  String localTypeString = "";
  String expandTypeTypeString = "";

  ShowMapTypePageState showMapTypePageState;

  MapFunctionSelectWidgetState(
      this.showMapTypePageState, this.mapTypeString, this.expandTypeSelectList);

  @override
  Widget build(BuildContext context) {
    return Wrap(children: mapTypeWidgetLists());
  }

  Widget titleTypeWidget(String title) {
    return Container(child: Text(title), alignment: Alignment.centerLeft);
  }

  List<Widget> mapTypeWidgetLists() {
    List<Widget> widgets = [];
    widgets.add(titleTypeWidget("地图类型(单选)"));
    widgets.addAll(mapTypeWidgetList());
    // widgets.add(titleTypeWidget("定位模式(单选)"));
    // widgets.addAll(localTypeWidgetList());
    widgets.add(titleTypeWidget("拓展功能(多选)"));
    widgets.addAll(expandTypeWidgetList());
    return widgets;
  }

  List<Widget> mapTypeWidgetList() {
    var list = mapTypeList.map((e) => GestureDetector(
                      behavior: HitTestBehavior.translucent,
        onTap: () {
          setState(() {
            mapTypeString = e;
            showMapTypePageState.setMapTypeString(mapTypeString);
          });
        },
        child: Container(
            decoration: BoxDecoration(
                border: Border.all(
                    color: mapTypeString == e
                        ? Color(0xff41BAB0)
                        : Color(0xff666666)),
                borderRadius: BorderRadius.circular(8)),
            padding: EdgeInsets.fromLTRB(16, 4, 16, 4),
            margin: EdgeInsets.fromLTRB(8, 8, 8, 8),
            child: Text(e,
                textAlign: TextAlign.center,
                style: TextStyle(
                    color: (mapTypeString == e
                        ? Color(0xff41BAB0)
                        : Color(0xff666666)))))));
    return list.toList();
  }

  List<Widget> localTypeWidgetList() {
    var list = localTypeList.map((e) => GestureDetector(
                      behavior: HitTestBehavior.translucent,
        onTap: () {
          setState(() {
            if (e != localTypeString) localTypeString = e;
            showMapTypePageState.setLocalTypeString(localTypeString);
          });
        },
        child: Container(
            decoration: BoxDecoration(
                border: Border.all(
                    color: localTypeString == e
                        ? Color(0xff41BAB0)
                        : Color(0xff666666)),
                borderRadius: BorderRadius.circular(8)),
            padding: EdgeInsets.fromLTRB(16, 4, 16, 4),
            margin: EdgeInsets.fromLTRB(8, 8, 8, 8),
            child: Text(e,
                textAlign: TextAlign.center,
                style: TextStyle(
                    color: (localTypeString == e
                        ? Color(0xff41BAB0)
                        : Color(0xff666666)))))));

    return list.toList();
  }

  List<Widget> expandTypeWidgetList() {
    var list = expandTypeList.map((e) => GestureDetector(
                      behavior: HitTestBehavior.translucent,
        onTap: () {
          setState(() {
            mapTypeString = "普通地图";
            if (expandTypeSelectList.contains(e)) {
              expandTypeSelectList.remove(e);
            } else {
              expandTypeSelectList.add(e);
            }
            showMapTypePageState.setExpandTypeSelectList(expandTypeSelectList);
          });
        },
        child: Container(
            decoration: BoxDecoration(
                border: Border.all(
                    color: expandTypeSelectList.contains(e)
                        ? Color(0xff41BAB0)
                        : Color(0xff666666)),
                borderRadius: BorderRadius.circular(8)),
            padding: EdgeInsets.fromLTRB(16, 4, 16, 4),
            margin: EdgeInsets.fromLTRB(8, 8, 8, 8),
            child: Text(e,
                textAlign: TextAlign.center,
                style: TextStyle(
                    color: (expandTypeSelectList.contains(e))
                        ? Color(0xff41bab0)
                        : Color(0xff666666))))));

    return list.toList();
  }

// List<Widget> typeWidgetList(
//     List<String> mapList, String type, bool equals, void Function() callback) {
//   var list = mapList.map((e) => GestureDetector(
 //                     behavior: HitTestBehavior.translucent,
//       onTap: () {
//         setState(() {
//           if (callback != null) callback();
//         });
//       },
//       child: Container(
//           decoration: BoxDecoration(
//               border: Border.all(color: Color(0xff666666)),
//               borderRadius: BorderRadius.circular(8)),
//           padding: EdgeInsets.fromLTRB(16, 4, 16, 4),
//           margin: EdgeInsets.fromLTRB(8, 8, 8, 8),
//           child: Text(e,
//               textAlign: TextAlign.center,
//               style: TextStyle(
//                   color: (type == e
//                       ? Color(0xff41BAB0)
//                       : Color(0xff666666)))))));
//
//   return list.toList();
// }
}
